/*
package com.jiazhong.filters;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Random;

@WebFilter("/goods/*")
public class DemoFilter implements Filter {
    public DemoFilter(){
        System.out.println("过滤器对象被创建....");
    }
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("过滤器初始化");
    }

    */
/**
     * 该方法用于实现过滤编辑的
     * 过滤器的过滤功能代码在该方法中编写
     * @param arg0   非HTTP协议的请求对象
     * @param arg1  非HTTP协议的相应对象
     * @param chain    过滤器链对象
     * @throws IOException
     * @throws ServletException
     *//*

    @Override
    public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chain) throws IOException, ServletException {
        //将请求和响应转化为基于Http协议的对象
        HttpServletRequest request=(HttpServletRequest) arg0;
        HttpServletResponse response=(HttpServletResponse) arg1;

        System.out.println("DemoFilter过滤器被执行");
        Random random=new Random();
        if (random.nextInt(10)%2==0){
            //放行
            chain.doFilter(request,response);
        }else {
            //跳转到首页
            response.sendRedirect("/index.jsp");
        }
    }

    @Override
    public void destroy() {
        System.out.println("过滤器被销毁");
    }
}
*/
